package org.docmanagement.data;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.docmanagement.commons.Constants;

@Entity
public abstract class Element extends Id implements Constants {

	private String title = null;
	private String description = null;
	private List<Category> categories = null;
	private List<Keyword> keywords = null;
	private static final char ELEMENT_TYPE = 'E';

	public Element() {
		super();
	}

	@javax.persistence.Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return super.getId();
	}

	public char getType() {
		return ELEMENT_TYPE;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Keyword> getKeywords() {
		return keywords;
	}

	public void setKeywords(List<Keyword> keywords) {
		this.keywords = keywords;
	}

	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> pCategories) {
		this.categories = pCategories;
	}

	public boolean equals(Object obj) {
		if (obj instanceof Element)
			return getId().equals(((Element) obj).getId());
		return false;
	}

	public int hashCode() {
		return getId().hashCode();
	}

	public String toString() {
		StringBuffer s = new StringBuffer();
		s.append(title).append(" (").append(getId());
		s.append(')');
		return s.toString();
	}

	public String toCompleteString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
